<?php
//armory data variables specifically for update
//set attributes into variables
//all field names should be in single quotes for consistency

//character attributes
//add titles
$name = $character['name'];
//$xml->characterInfo->character->attributes()->prefix . " " . $character['name'] . " " 
//. $xml->characterInfo->character->attributes()->suffix;
//$charurl = $xml->characterInfo->character->attributes()->charUrl;
$level = $character['level'];
$points = $character['achievementPoints'];
$lastLogin = date('Y-m-d',(substr($character['lastModified'],0,10)));
$guildName = $character['guild']['name'];
$race = $character['race'];
$genderid = $character['gender'];
$raceid = $character['race'];
$classid = $character['class'];
$itemLevel = $character['items']['averageItemLevel'];

//put possible races into arrays
include 'raceClass.php';

//set the faction and race by looking through the arrays
if (array_key_exists($race,$horde))
{
$faction = 'Horde';
$race = $horde[$race];
}
else
{
$faction = 'Alliance';
$race = $alliance[$race];
}

//convert class number to name			
$class = $character['class'];

//class_a to be found in includedd file
				
$class = $class_a[$class];

//build character image general and URL to use on other pages
//e.g. http://us.battle.net/static-render/us/magtheridon/207/65951439-avatar.jpg	
$image = $character['thumbnail'];
$imgUrl = "http://us.battle.net/static-render/us/".str_replace("225", "56", $image);
//replace single quotes to allow armory url to work correctly
$realmUrl = str_replace("'","",$realm);

//build image url as a variable to use on other pages
$armoryUrl = "<a target='_blank' href='http://us.battle.net/wow/en/character/" . $realmUrl . "/" . 
$char . "/simple'><img src='" . $imgUrl . "' height='100'/></a>";

//$talent1 = $character[talents][0][name];
$characterTalents = $character['talents'];
$talent1 = xml_blank($characterTalents, 0, 'name');
$talent2 = xml_blank($characterTalents, 1, 'name');

//put skills and professions into several arrays
//first professions...
$characterProfs = $character['professions']['primary'];

/*
profession ids
182 = herbalism
186 = mining
393 = skinning

164 = blacksmithing
165 = leatherworking
171 = alchemy
197 = tailoring
202 = engineering
333 = enchanting
755 = jewelcrafting
773 = inscription

185 = cooking
129 = first aid
*/

//define profession ids that have recipes as array
$recipeProfs = array(1=>164, 2=>165, 3=>171, 4=>197, 5=>202, 6=>333, 7=>755, 8=>773, 9=>185, 10=>129);

$profIds = array($characterProfs[0]['id'], $characterProfs[1]['id']);
//skill name
$prof = array ( 0 => xml_blank($characterProfs, 0, 'name'), 1 =>
		xml_blank($characterProfs, 1, 'name')
			);
//skill level
$profval = array ( 0 => xml_blank($characterProfs, 0, 'rank'), 1 =>
		xml_blank($characterProfs, 1, 'rank')
			);
//max skill level
$profmax = array ( 0 => xml_blank($characterProfs, 0, 'max'), 1 =>
		xml_blank($characterProfs, 1, 'max')
			);
			
//secondary skills
$characterSkills = $character['professions']['secondary'];

$skill  = array (
			0 => xml_blank($characterSkills, 0, 'name'),
			1 => xml_blank($characterSkills, 1, 'name'),
			2 => xml_blank($characterSkills, 2, 'name'),
			3 => xml_blank($characterSkills, 3, 'name')
			);

$skillval  = array (
			0 => xml_blank($characterSkills, 0, 'rank'),
			1 => xml_blank($characterSkills, 1, 'rank'),
			2 => xml_blank($characterSkills, 2, 'rank'),
			3 => xml_blank($characterSkills, 3, 'rank')
			);

$skillmax  = array (
			0 => xml_blank($characterSkills, 0, 'max'),
			1 => xml_blank($characterSkills, 1, 'max'),
			2 => xml_blank($characterSkills, 2, 'max'),
			3 => xml_blank($characterSkills, 3, 'max')
			);

//thin out reputation into an array for only neutral and higher
foreach ($character['reputation'] as $rep)

{
	if ($rep['value']>0 && $rep['standing']>0)//standing is neutral or better 
	{
	$rep_ar[] = array($rep['id'] . ", " . $rep['name'] . ", " . 
	$rep['standing'] . ", " . $rep['value'] . ", " . $rep['max']);
	//build array as follows 'id,name,standing,value,max'
	}
}

//character stats
//bars
$characterStats = $character['stats'];

$health = $characterStats['health'];
$bartype = $characterStats['powerType'];
$regen_combat = $characterStats['mana5Combat'];
$regen_nocombat = $characterStats['mana5'];
$mana = $characterStats['power'];

//strength
$strength = $characterStats['str'];

//agility
$agility = $characterStats['agi'];

//stamina
$stamina = $characterStats['sta'];

//intellect
$intellect = $characterStats['int'];

//spirit
$spirit = $characterStats['spr'];

//armor
$armor = $characterStats['armor'];

//weapons and hand items
$main_dps = $characterStats['mainHandDps'];
$main_max = $characterStats['mainHandDmgMax'];
$main_min = $characterStats['mainHandDmgMin'];
$main_speed = $characterStats['mainHandSpeed'];

$off_dps = $characterStats['offHandDps'];
$off_max = $characterStats['offHandDmgMax'];
$off_min = $characterStats['offHandDmgMin'];
$off_speed = $characterStats['offHandSpeed'];

$power = $characterStats['attackPower'];

$hitRating = $characterStats['hitRating'];
	
$critchance_rating = $characterStats['critRating'];
$critchance_percent = $characterStats['crit'];

$ranged_dps = $characterStats['rangedDps'];
$ranged_max = $characterStats['rangedDmgMax'];
$ranged_min = $characterStats['rangedDmgMin'];
$ranged_speed = $characterStats['rangedSpeed'];
$ranged_power = $characterStats['rangedAttackPower'];

//begin achievement data parsing
$characterAchievements = $character['achievements'];			
$characterReputation = $character['reputation'];

			


?>